<?php
//include('../lib/log4php/Logger.php');
//Logger::configure('../log/logconfig.xml');

include 'UserLoginInterface.php';
include '../model/UserLoginModel.php';
include '../model/UserProfileModel.php';
class UserLoginImplement implements UserLoginInterface {
    private $log;
    public function __construct(){
       $this->log = Logger::getLogger(__CLASS__); 
    }
    
    public function userLogin($userId,$password){
        
        try{
            $userLogin = new UserLoginModel();
            $userLogin->setUserId($userId);
            $userLogin->setPassword($password);
            $this->log->info($userLogin->toString());
            $response = $userLogin->userLogin();
            // get User Profile
            $userProfile = new UserProfileModel();
            $userProfile->setUserId($userId);
            $userProfileResponse = $userProfile->getUserProfileById();
            $this->log->info($userProfile->toString());
            if($userProfileResponse['loginResponseHeader']['responseCode'] == "0"){
                $response['loginResponseDetail'] = $userProfileResponse['loginResponseDetail'];
                return $response;
            }else{
                return $userProfileResponse;
            }
        }catch(Exception $e){
            $dateTime = date("Y-m-d h:i:s A");
            $refId = rand(10,10000000);
            $response = array();
            $response['loginResponseHeader'] = array( 'refId' => $refId, 'dateTime' => $dateTime,'responseCode'=>'1','responseDesc'=>$e->getMessage());
            $response['loginResponseDetail'] = array( 'firstname' => '', 'lastname' => '','rolelist'=>'');
            $this->log->error($e->getMessage());
            return $response;
        }
    }
}

/*
$login = new UserLoginImplement();
print_r($login->userLogin("aot.maha@gmail.com", "password"));
*/
?>
